package com.hakim.wfb.customer.service.impl;

import com.hakim.wfb.bean.PointOrder;
import com.hakim.wfb.biz.PointOrderBiz;
import com.hakim.wfb.customer.params.trans.GetPointOrderParameter;
import com.hakim.wfb.customer.params.trans.GetProfitPointOrderParameter;
import com.hakim.wfb.customer.result.trans.PointOrderView;
import com.hakim.wfb.customer.service.PointOrderService;
import com.hakim.wfb.customer.service.convert.PointOrderDtv;
import com.hkfs.fundamental.api.data.ListResultEx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/7/6.
 */
@Service("pointOrderService")
public class PointOrderServiceImpl implements PointOrderService {

    @Autowired
    private PointOrderBiz pointOrderBiz;

    @Override
    public ListResultEx<PointOrderView> getPointOrders(GetPointOrderParameter param) {

        ListResultEx<PointOrderView> result = new ListResultEx<>();
        if (param.getSessionIdentity() == null || param.getSessionIdentity().getUuid() == null || param.getSessionIdentity().getUuid().equals(""))
            return result.makeFailedResult();

        List<PointOrderView> listView = new ArrayList<>();
        List<PointOrder> list = pointOrderBiz.getPointOrders(param);

        //json重整
        for (int i = 0; i < list.size(); i++) {
            listView.add(PointOrderDtv.convert(list.get(i)));
        }
        result.setPageSize(param.getPageSize());
        result.setPageNo(param.getPageNo());
        result.setDataList(listView);
        result.setTotalCount(pointOrderBiz.getPointOrderCount(param));
        return result.makeSuccessResult();
    }

    @Override
    public ListResultEx<PointOrderView> getProfitPointOrders(GetProfitPointOrderParameter param) {
        ListResultEx<PointOrderView> result = new ListResultEx<>();

        if (param.getSessionIdentity() == null || param.getSessionIdentity().getUuid() == null || param.getSessionIdentity().getUuid().equals(""))
            return result.makeFailedResult();

        List<PointOrderView> listView = new ArrayList<>();
        List<PointOrder> list = pointOrderBiz.getProfitPointOrders(param);

        //json重整
        for (int i = 0; i < list.size(); i++) {
            listView.add(PointOrderDtv.convert(list.get(i)));
        }
        result.setPageSize(param.getPageSize());
        result.setPageNo(param.getPageNo());
        result.setDataList(listView);
        result.setTotalCount(pointOrderBiz.getProfitPointOrderCount(param));
        return result.makeSuccessResult();
    }
}
